<template>
  <div class="cate-gory-tab">
    <div class="tab-main">
      <div class="tab-main-item" v-for="(item, index) in categoryList" :key="item.id" @click="tabClick(item)">
        <span :class="currentIndex == index ? 'active' : ''">{{ item.name }}</span>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    categoryList: {
      type: Array,
      default() {
        return [];
      },
    },
  },
  data() {
    return {
      currentIndex: 0,
    }
  },
  methods: {
    tabClick(item) {
      let index = this.categoryList.findIndex(items => items.id == item.id);
      this.currentIndex = index;
      let id = this.categoryList[index].id
      // console.log(index, id)
      this.$emit('tabClick', id)
    }
  }
};
</script>

<style lang="scss" scoped>
.cate-gory-tab {
  width: 20%;
}
.tab-main {
  // width: 20%;
  .tab-main-item {
    // padding: 15px 20px;
    height: 45px;
    font-size: 14px;
    span {
      padding: 15px 20px;
    }
    .active {
      color: #B32B2B;
      border-left: 2px solid #B32B2B;
      font-size: 16px;
    }
  }
}
</style>